/*
 * TaskMng.cpp
 *
 *  Created on: Dec 20, 2011
 *      Author: quotrader
 */

#include "TaskMng.h"
#include "TaskList.h"
#include <stdio.h>

TaskMng::TaskMng() {
	this->numMaxTask	= MAXTASK;
	this->numTask		= TASKCOUNT;
	this->tasks			= new Task[this->numMaxTask];
	this->changed		= true;
	//this->finishAll		=false;
}


void TaskMng::loadTask(Scale *s){

	taskStruct fileList[MAXTASK];
	getTasksFromtaskList(fileList);

	//convert tasks list to be object of TASK class
	for (int i = 0; i < this->numTask; i++)
		this->tasks[i].InitTask(fileList[i].pExecutionTime, fileList[i].pPeriod, s,i+1);

}


Task* TaskMng::getAllTasks(){
	return this->tasks;
}


Task TaskMng::getTask(int index){
	return this->tasks[index];
}


void TaskMng::addTask(Task task, int index=-1){

	if (this->numTask >= this->numMaxTask) return;

	if(index >= 0)this->tasks[index]=task;
	else this->tasks[this->numTask]=task;

	this->numTask++;
	this->changed=true;
}

void TaskMng::setTask(Task task, int index){

	this->tasks[index]=task;
	this->changed=true;
}
